package cn.com.panda.utils;

import android.content.Context;

public class DataCacheUtil {
    private static SharedPreferencesUtil mSharedPreferencesUtil;
    private static DataCacheUtil dataCacheUtil;

    private DataCacheUtil(){

    }

    public static DataCacheUtil newInstance(){
        if(dataCacheUtil == null){
            synchronized (DataCacheUtil.class){
                if(dataCacheUtil == null)
                    dataCacheUtil = new DataCacheUtil();
            }
        }
        return dataCacheUtil;
    }

    public void attachContext(Context context){
        if(context == null)
            return;
        mSharedPreferencesUtil = new SharedPreferencesUtil(context);
    }

    public void saveString(String key, String value){
        if(mSharedPreferencesUtil == null)
            return;
        mSharedPreferencesUtil.saveString(key,value);
    }
    public String getString(String key){
        if(mSharedPreferencesUtil == null)
            return null;
        return mSharedPreferencesUtil.getString(key);
    }

    public void saveBoolean(String key, Boolean value){
        if(mSharedPreferencesUtil == null)
            return;
        mSharedPreferencesUtil.saveBoolean(key,value);
    }
    public Boolean getBoolean(String key){
        if(mSharedPreferencesUtil == null)
            return null;
        return mSharedPreferencesUtil.getBoolean(key);
    }

    public void saveLong(String key, Long value){
        if(mSharedPreferencesUtil == null)
            return ;
        mSharedPreferencesUtil.saveLong(key,value);
    }
    public Long getLong(String key){
        if(mSharedPreferencesUtil == null)
            return Long.MIN_VALUE;
        return mSharedPreferencesUtil.getLong(key);
    }
}
